
#include "Normal.hpp"
#include <stdexcept>
#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;

int
main ( int argc, char* argv[], char* env[] )
{
  //vector<int> iarg(20,0);
  //  for ( int i=1; i < argc; ++i )
  //iarg[i-1] = atoi(argv[i]);

  try
    {
      // generate some uniform RV
      int n = 10000;

      // if ( iarg[0] > 0 )
      // 	n = iarg[0];

      cout << "generating " << n << " random variables" << endl;

      Random* RV = new Normal;
      double xsum=0,xsumsq=0;
      for ( int i = 0; i < n; ++i )
	{
	  double x = RV->rand();
	  //cout << x << endl;
	  xsum += x;
	  xsumsq += x*x;
	}
      double mean = xsum / n;
      double stddev = ( xsumsq - n * mean * mean ) / ( n - 1 );
      cout << "mean = " << mean << ", stddev = " << stddev << endl;
      
      double x = 0.5;
      if ( argc > 1 )
	x = atof(argv[1]);

      // check inverse functions
      double y = RV->InvCDF(x);
      double yp = RV->CDF(y);
      cout << x << ", " << y << ", " << yp << endl;

    }
  catch ( std::exception& ex )
    {
      cerr << ex.what() << endl;
    }
  return 0;
}
